	import pinyin from "js-pinyin";

	export const area = {
		110100: '北京市',
		120100: '天津市',
		130100: '石家庄市',
		130200: '唐山市',
		810100: '香港岛',
		810200: '九龙',
		810300: '新界',
		820100: '澳门半岛',
		820200: '离岛',
	}

	export const generateAreaList = (areaList) => {
		pinyin.setOptions({
			checkPolyphone: false,
			charCase: 0
		});
		let dict = new Map();
		if (Array.isArray(areaList)) {
			areaList.forEach(item => {
				let key = pinyin.getFullChars(item.city_name)
				let first = key[0];
				!dict.has(first) && dict.set(first, []);
				let nameArr = item.city_name.split('')
				dict.get(first).push({
					code: item.id,
					name: item.city_name,
					p: nameArr.map(k => pinyin.getFullChars(k).toLocaleLowerCase())
				});
			})
			return dict
		}

		Object.entries(area).forEach((item) => {
			let key = pinyin.getFullChars(item[1])
			let first = key[0];
			!dict.has(first) && dict.set(first, []);
			let nameArr = item[1].split('')
			dict.get(first).push({
				code: item[0],
				name: item[1],
				p: nameArr.map(k => pinyin.getFullChars(k).toLocaleLowerCase())
			});
		});

		// return Object.entries(dict).sort((a, b) => a[0].localeCompare(b[0])); // 数组形式返回
		return dict // 返回map
	}